package com.sisyphus.spinach.extension.form;

/**
 * 大小
 */
public class Size implements IFormRule {

    private final int size, min, max;
    private final CharSequence errorMessage;

    public Size(int size, int min, CharSequence errorMessage) {
        this(size, min, Integer.MAX_VALUE, errorMessage);
    }

    public Size(int size, int min, int max, CharSequence errorMessage) {
        this.size = size;
        this.min = min;
        this.max = max;
        this.errorMessage = errorMessage;
    }

    @Override
    public boolean validation() {
        return size <= max && size >= min;
    }

    @Override
    public CharSequence getErrorMessage() {
        return errorMessage;
    }

}
